package edu.ccut.saturn.component.impl;

import java.util.List;

import edu.ccut.saturn.component.IComponent;
import edu.ccut.saturn.component.IComponentInfo;
import edu.ccut.saturn.component.ILogger;
import edu.ccut.saturn.component.IParameterInfo;
import edu.ccut.saturn.component.SaturnComponentException;
import edu.ccut.saturn.component.SaturnLoggerManager;
import edu.ccut.saturn.component.xml.ISaturnElement;

/**
 * {@link IComponentInfo} Abstract implementation
 * 
 * @see IComponentInfo
 * @author LeslieGu
 * 
 */
public abstract class AbstractComponentInfo implements IComponentInfo {

	private static final String LOGGER_KEY_LOAD_BUNDLE = SaturnLoggerManager.LOGGER_KEY_LOAD_BUNDLE;

	protected static ILogger logger = SaturnLoggerManager.getInstance()
			.getSaturnLogger(LOGGER_KEY_LOAD_BUNDLE);

	private String symbolicName;

	private String key;

	private String name;

	private String description;

	private List<IParameterInfo> parameterInfos;

	private String loadStart;
	
	public String getLoadStart() {
		return loadStart;
	}

	public void setLoadStart(String loadStart) {
		this.loadStart = loadStart;
	}

	public AbstractComponentInfo() {
	}

	public AbstractComponentInfo(String symbolicName, String key, String name,
			String description, List<IParameterInfo> parameterInfos, String loadStart) {

		this.symbolicName = symbolicName;
		this.key = key;
		this.name = name;
		this.description = description;
		this.parameterInfos = parameterInfos;
		this.loadStart = loadStart;
	}

	public String getBundleSymbolicName() {
		return symbolicName;
	}

	public void setBundleSymbolicName(String symbolicName) {
		this.symbolicName = symbolicName;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getFullKey() {
		return this.symbolicName + KEY_SEPARATOR + this.key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<IParameterInfo> getParameterInfos() {
		return parameterInfos;
	}

	public void setParameterInfos(List<IParameterInfo> parameterInfos) {
		this.parameterInfos = parameterInfos;
	}

	public String toXmlStr() {
			ISaturnElement saturnElement = toSaturnElement();
			return saturnElement.getXMLStr();
	}

	public abstract ISaturnElement toSaturnElement();

	public abstract IComponent createComponent() throws SaturnComponentException;

	public String toString() {
		StringBuffer stringBuffer = new StringBuffer("[key=" + this.key + "] "
				+ this.name + " " + this.description);

		if (this.parameterInfos != null) {
			stringBuffer.append(" <parameters:");

			for (IParameterInfo parameterInfo : this.parameterInfos) {
				stringBuffer.append(parameterInfo).append(", ");
			}
			stringBuffer.deleteCharAt(stringBuffer.length() - 1);
			stringBuffer.append(">");
		}

		return stringBuffer.toString();
	}
}
